package com.example.workrecord.util.dingtalkopenapi.chat;

import com.alibaba.fastjson.JSONObject;
import com.example.workrecord.util.dingtalkopenapi.utils.HttpUtil;
import com.example.workrecord.util.dingtalkopenapi.utils.JsonUtils;

import java.util.Map;

/**
  *@ClassName: ChatHelper
  *@Description 钉钉群会话相关接口
  *@Author Mr.Bu
  *@Date 2019/12/18 9:31
  *@Version: 1.0
  */
public class ChatHelper {

    public static Map<String, Object> createChat(String accessToken, JSONObject obj) throws Exception {
        String url = "https://oapi.dingtalk.com/chat/create?access_token=" + accessToken;
        String strResult = HttpUtil.doPostObj(url, obj);
        Map<String, Object> result = JsonUtils.getMap(strResult);
        return result;
    }

    public static Object updateChat(String accessToken, JSONObject res)  throws Exception{
        String url = "https://oapi.dingtalk.com/chat/update?access_token=" + accessToken;
        String strResult = HttpUtil.doPostObj(url, res);
        Map<String, Object> result = JsonUtils.getMap(strResult);
        return result;
    }

    public static Map<String,Object> getChat(String accessToken, String res) throws Exception{
        String url = "https://oapi.dingtalk.com/chat/get?access_token=" + accessToken+"&chatid="+res;
        String strResult = HttpUtil.doGet(url);
        Map<String, Object> result = JsonUtils.getMap(strResult);
        return result;
    }
}
